<?php

namespace app\modules\setting\models\yjrwsz;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper;
use app\modules\setting\models\yjrwsz\EtcRules;
use yii\helpers\Json;

/**
 * EtcRulesSearch 是 `app\modules\setting\models\yjrwsz\EtcRules` 的搜索模型.
 */
class EtcRulesSearch extends EtcRules
{

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // 绕过scenario()在父类中的实现
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @param integer $pageSize
     *
     * @return ActiveDataProvider
     */
    public function search($params,$select=null)
    {
        $query = EtcRules::find()->select($select ? $select : "*");

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => ['pageSize' => ArrayHelper::getValue($params,"pageSize",10),'defaultPageSize' => 10,'pageSizeParam' => 'pageSize'],
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
        ]);

        $this->load($params,"");

        if (!$this->validate()) {
            // 如果您不想在验证失败时返回任何记录，请取消下面一行的注释
            // $query->where('0=1');
            return $dataProvider;
        }

        // 过滤条件
        $query->andFilterWhere([
            'id' => $this->id,
        ]);


                $query->andFilterWhere(['like', 'name', $this->name])                                ->andFilterWhere(['like', 'creators_per_job', $this->creators_per_job])
                                ->andFilterWhere(['like', 'product_num', $this->product_num])
                                ->andFilterWhere(['like', 'goods_per_store', $this->goods_per_store])
                                ->andFilterWhere(['like', 'min_sale', $this->min_sale])
                                ->andFilterWhere(['like', 'min_price', $this->min_price])
                                ->andFilterWhere(['like', 'min_pf', $this->min_pf])
                                ->andFilterWhere(['like', 'min_yj', $this->min_yj])
                                ->andFilterWhere(['like', 'is_bp', $this->is_bp])
                                ->andFilterWhere(['like', 'is_new', $this->is_new])
                                ->andFilterWhere(['like', 'is_brand', $this->is_brand])
                                ->andFilterWhere(['like', 'drsj', $this->drsj])
                                ->andFilterWhere(['like', 'create_at', $this->create_at]);
            
        return $dataProvider;
    }
}
